<template>
  <dt-modal-edit ref="modal" title="确认提交" :label-width="90" :width="450" @ok="onOk" :loading="loading">
    <p slot="bottom">确认提交后，将无法退回，请注意核对信息。</p>
  </dt-modal-edit>
</template>

<script>
  import ruleOpt from '@/biz/option/rule.js'
  import settlementMgr from '@/biz/commission/settlement.js'

  export default {
    data() {
      return {
        loading: false,
        options: [
          {
            title: '入账公司',
            key: 'accountingCompany',
            select: {
              options: this.$dt.dictInfo().accountingCompany.map((i) => ({
                key: i.value,
                value: i.value
              })),
              filterable: true
            },
            rules: [ruleOpt.required('请选择入账公司')]
          }
        ],
        info: {}
      }
    },
    methods: {
      show(info) {
        this.info = info
        this.$refs.modal.show(this.options, this.info)
      },
      hide() {
        this.$refs.modal.hide()
      },
      onOk() {
        this.loading = true
        settlementMgr
          .save(this.info)
          .then((res) => {
            this.$Message.success('提交成功')
            this.loading = false
            this.$emit('success')
            this.hide()
          })
          .catch((err) => {
            this.loading = false
            // 佣金单已被撤回
            if (err.code == 5001) {
              this.$store.commit('deleteroutefun', this.$route.meta.title)
              this.$router.push({
                path: '/commission/information'
              })
            }
          })
      }
    }
  }
</script>

<style></style>
